const KoaRouter = require('koa-router');
const Template = require('../util/Template');
const HttpClient = require('../util/HttpClient')

const modules = require('../../modules');
const router = new KoaRouter();

// 日程
router.get('/calendar', async ctx => {
  let script = ['/calendar.index.js'];
  let modConfig = modules['calendar.index'];
  let reqHeaders = ctx.request.headers;

  let result = await HttpClient.request('/calendar', 'get', null, {headers: reqHeaders});
  let body = result.body;
  ctx.body = await Template.renderWithHtml('日程管理', body, script, modConfig.template, ctx);
})

router.get('/calendar/noAuth', async ctx => {
  let script = ['/calendar.noAuth.js'];
  let modConfig = modules['calendar.noAuth'];
  let reqHeaders = ctx.request.headers;

  let result = await HttpClient.request('/calendar', 'get', null, {headers: reqHeaders});
  let body = result.body;
  ctx.body = await Template.renderWithHtml('日程管理', body, script, modConfig.template, ctx);
})

module.exports = router;